<template>
  <div class="oem" style="width:100%;">
    <!-- 查询条件 -->
    <div class="oem-box query-box">
        <el-form :model="dataForm" ref="dataForm">
            <el-row>
              <el-col :span="4">
                <div class="depart-box">
                  <div class="slect-title">OEM卡类型</div>
                  <el-select v-model="dataForm.cardType"  filterable placeholder="请选择" clearable>
                    <el-option
                      v-for="item in oemType"
                      :key="item.key"
                      :label="item.value"
                      :value="item.key">
                    </el-option>
                  </el-select>
                </div>
              </el-col>
              <el-col :span="4">
                <el-form-item prop="cardNumber">
                  <el-input v-model="dataForm.cardNumber" placeholder="请输入OEM卡号">
                    <template slot="prepend">OEM卡号</template>
                  </el-input>
                </el-form-item>
              </el-col>
                <el-col :span="4">
                  <div class="depart-box">
                    <div class="slect-title">分配至</div>
                    <el-select v-model="value"  filterable placeholder="请选择" clearable @change="change(value)" value-key="id">
                        <el-option
                          v-for="item in branchcenter"
                          :key="item.id"
                          :label="item.name"
                          :value="item.id">
                        </el-option>
                      </el-select>
                  </div>
                </el-col>
              <el-col :span="4">
                  <div class="depart-box">
                    <div class="slect-title">是否激活</div>
                      <el-select v-model="dataForm.activationStatus"  filterable placeholder="请选择" clearable>
                        <el-option
                          v-for="item in oemStatus"
                          :key="item.key"
                          :label="item.value"
                          :value="item.key">
                        </el-option>
                      </el-select>
                  </div>
                </el-col>
              <el-col :span="4">
                <el-form-item prop="remark">
                  <el-input v-model="dataForm.remark" placeholder="其输入内容">
                    <template slot="prepend">备注</template>
                  </el-input>
                </el-form-item>
              </el-col>
            </el-row>
          <el-row>
            <el-col :span="4">
                <div class="depart-box">
                  <div class="slect-title">OEM卡种类</div>
                  <el-select v-model="dataForm.cardFrom"  filterable placeholder="请选择" clearable>
                    <el-option
                      v-for="item in cardFromOption"
                      :key="item.key"
                      :label="item.value"
                      :value="item.key">
                    </el-option>
                  </el-select>
                </div>
            </el-col>
            <el-col :span="6">
              <div class="depart-box">
                <div class="slect-title">创建时间</div>
                <el-date-picker
                      v-model="dataForm.createDate"
                      type="daterange"
                      start-placeholder="开始日期"
                      end-placeholder="结束日期"
                      :default-time="['00:00:00', '23:59:59']" value-format="yyyy-MM-dd HH:mm:ss" format="yyyy-MM-dd HH:mm:ss">
                </el-date-picker>
              </div>
            </el-col>
            <el-col :span="8">
              <el-form-item label prop="remark">
                <el-row>
                  <el-col :span="12">
                    <el-input v-model="dataForm.startCardNumber" placeholder="开始卡段">
                      <template slot="prepend">OEM卡段</template>
                    </el-input>
                  </el-col>
                  <el-col class="line" :span="1">-</el-col>
                  <el-col :span="8">
                    <el-input v-model="dataForm.endCardNumber" placeholder="结束卡段">
                    </el-input>
                  </el-col>
                </el-row>
                </el-input>
              </el-form-item>
            </el-col>
            
            <!-- <el-col :span="12">
              <el-form-item prop="remark">
                <div class="depart-date">
                  <div class="slect-title">创建时间</div>
                  <el-date-picker
                    v-model="dataForm.createDate"
                    type="daterange"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期"
                    :default-time="['00:00:00', '23:59:59']" value-format="yyyy-MM-dd HH:mm:ss" format="yyyy-MM-dd HH:mm:ss">
                  </el-date-picker>
                </div>
              </el-form-item>
            </el-col> -->
          </el-row>
        </el-form>
      <div class="from-btns">
        <kt-button :label="$t('action.reset')" @click="resetForm('dataForm')" perms="true"   type="primary"  />
        <kt-button :label="$t('action.search')" @click="searchForm"  :loading="editLoading" perms="true"  type="primary"  />
      </div>
    </div>
    <div class="add-btns">
      <kt-button :label="$t('action.batchdistribution')" perms="OEM:OEM:distribution" :disabled="this.selections.length===0" @click="batchDistributionoem" type="primary" />
      <kt-button :label="$t('action.exportExcel')" perms="OEM:OEM:exportExcel" @click="exportOem"  type="primary" />
    </div>
    <div class="fr">
      <kt-button :label="$t('下载更新模板')" perms="OEM:OEM:downloadUpdate" type="primary" @click="downloadUpdate" ></kt-button>
      <kt-button :label="$t('批量更新信息')" perms="OEM:OEM:update" :loading='importIsSuccess2' type="primary" @click="batchUpdate" ></kt-button>
      <kt-button :label="$t('action.download-tmpl')" @click="download" perms="OEM:OEM:download" type="primary"></kt-button>
      <kt-button  :label="$t('action.batchimport')" :disabled='importIsSuccess' @click="batchImport" perms="OEM:OEM:batchimport" type="primary" ></kt-button>
      <kt-button :label="$t('action.add-oem')" perms="OEM:OEM:add" type="primary" @click="handleAdd" ></kt-button>
    </div>
    <kt-table permsEdit="OEM:OEM:edit" OEM  permsDelete="OEM:OEM:delete" permsDistribution="OEM:OEM:distribution"
              :data="pageResult" :columns="columns"
              @findPage="findPage" @handleEdit="handleEdit" @handleDelete="handleDelete" @handleBatchDelete="handleBatchDelete"
              @distributionoem="distributionoem" @selectionChange="selectionChange">
    </kt-table>

    <!--新增编辑弹窗-->
    <el-dialog class="addNew" :title="operation?'生成OEM卡':'编辑OEM卡'" width="40%" :visible.sync="dialogVisible" :close-on-click-modal="false">
      <el-form :model="dataFormAdd" label-width="100px" :rules="dataFormRules" ref="dataFormAdd" :size="size">
        <el-form-item label="ID" prop="id" v-if="false">
          <el-input v-model="dataFormAdd.id" :disabled="true" auto-complete="off"></el-input>
        </el-form-item>
        <el-row v-if="!dataFormAdd.id">
          <el-col :span="5">
            <span>生成数量：</span>
          </el-col>
          <el-col :span="18">
            <el-input v-model="dataFormAdd.openNumber" auto-complete="off"></el-input>
          </el-col>
        </el-row>
        <el-row v-if="dataFormAdd.id">
          <el-col :span="5">
            <span>OEM卡号：</span>
          </el-col>
          <el-col :span="18">
            <el-input v-model="dataFormAdd.cardNumber" auto-complete="off"></el-input>
          </el-col>
        </el-row>
        <el-row  v-if="dataFormAdd.id">
          <el-col :span="5">
            <span>OEM密码：</span>
          </el-col>
          <el-col :span="18">
            <el-input v-model="dataFormAdd.cardPassword" auto-complete="off"></el-input>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="5">
            <span>OEM类型：</span>
          </el-col>
          <el-col :span="18">
            <el-select style="width:100%" v-model="value3"  filterable placeholder="请选择" clearable @change="changeoemType(value3)">
              <el-option
                v-for="item in oemType"
                :key="item.key"
                :label="item.value"
                :value="item.key">
              </el-option>
            </el-select>
          </el-col>
        </el-row>
        <el-row v-if="!dataFormAdd.id">
          <el-col :span="5">
            <span>OEM种类：</span>
          </el-col>
          <el-col :span="18">
          <el-select style="width:100%" v-model="cardFrom"  filterable placeholder="请选择"  @change="changecardFrom(cardFrom)">
              <el-option
                v-for="item in cardFromOption"
                :key="item.key"
                :label="item.value"
                :value="item.key">
              </el-option>
            </el-select>
          </el-col>
        </el-row>
        <el-row v-if="dataFormAdd.id">
          <el-col :span="5">
            <span>OEM种类：</span>
          </el-col>
          <el-col :span="18">
          <el-select style="width:100%" :disabled="true" v-model="cardFrom"  filterable placeholder="请选择"  @change="changecardFrom(cardFrom)">
              <el-option
                v-for="item in cardFromOption"
                :key="item.key"
                :label="item.value"
                :value="item.key">
              </el-option>
            </el-select>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="5">
            <span>科目：</span>
          </el-col>
          <el-col :span="18">
            <el-select v-model="dataFormAdd.subject"  filterable placeholder="请选择" clearable
                    style="width: 100%;">
            <el-option
              v-for="item in oemSubject"
              :key="item.key"
              :label="item.value"
              :value="item.key">
            </el-option>
          </el-select>
          </el-col>
        </el-row> 
        <el-row>
          <el-col :span="5">
            <span>有效期:</span>
          </el-col>
          <el-col :span="18">
            <el-date-picker
              style="width:100%"
              v-model="activationDate"
              type="daterange"
              :start-placeholder="'开始时间'"
              :end-placeholder="'结束时间'"
              :picker-options="pickerOptions"
              :default-time="['00:00:00', '23:59:59']" value-format="yyyy-MM-dd HH:mm:ss" format="yyyy-MM-dd HH:mm:ss">
            </el-date-picker>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="5">
            <span>使用方式：</span>
          </el-col>
          <el-col :span="18">
            <el-select v-model="dataFormAdd.useType" :disabled="operation?false:true" @change="useTypeChange" filterable placeholder="请选择" clearable
                    style="width: 100%;">
            <el-option
              v-for="item in useWay"
              :key="item.key"
              :label="item.value"
              :value="item.key">
            </el-option>
          </el-select>
          </el-col>
        </el-row> 
        <el-row v-if='isSchoolType'>
          <el-col :span="5">
            <span>学校：</span>
          </el-col>
          <el-col :span="18">
            <el-select @change="schoolChange" v-model="dataFormAdd.schoolId" :disabled="operation?false:true" filterable placeholder="请选择" clearable
                    style="width: 100%;">
            <el-option
              v-for="item in school_option"
              :key="item.id"
              :label="item.schoolName"
              :value="item.id">
            </el-option>
          </el-select>
          </el-col>
        </el-row> 
        <el-row >
            <el-col :span="5">
              <span>三方：</span>
            </el-col>
            <el-col :span="18">
              <el-select v-model="dataFormAdd.frontUserId" filterable placeholder="请选择" clearable
                      style="width: 100%;">
              <el-option
                v-for="item in SF_option"
                :key="item.id"
                :label="item.userName"
                :value="item.id">
              </el-option>
            </el-select>
            </el-col>
          </el-row>
          <el-row v-if='isSchoolType'>
            <el-col :span="5">
              <span>班级名称：</span>
            </el-col>
            <el-col :span="18">
              <el-input v-model="dataFormAdd.clazzName"></el-input>
            </el-col>
          </el-row> 
        <el-row v-if="!dataFormAdd.id">
          <el-col :span="5">
            <span>分配至：</span>
          </el-col>
          <el-col :span="18">
            <popup-tree-input
              :data="assignmentType" :props="oemStatusProps" :prop="dataFormAdd.assignmentTypevalue"
              :currentChangeHandle="handleTreeSelectChange3Add">
            </popup-tree-input>
          </el-col>
        </el-row>
        <el-row v-if="!dataFormAdd.id&dataFormAdd.assignmentType == 1">
          <el-col :span="5">
            <span>分中心：</span>
          </el-col>
          <el-col :span="18">
            <el-select v-model="value2"  filterable placeholder="请选择"  @change="changeAdd(value2)" value-key="id" style="width: 100%;">
                <el-option
                  v-for="item in branchcenter"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id">
                </el-option>
            </el-select>
          </el-col>
        </el-row>
        <el-row v-if="!dataFormAdd.id&dataFormAdd.assignmentType == 1">
          <el-col :span="5">
            <span>分中心：</span>
          </el-col>
          <el-col :span="18">
            <el-select v-model="value2"  filterable placeholder="请选择"  @change="changeAdd(value2)" value-key="id" style="width: 100%;">
                <el-option
                  v-for="item in branchcenter"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id">
                </el-option>
            </el-select>
          </el-col>
        </el-row>
        <el-row v-if="!dataFormAdd.id&dataFormAdd.assignmentType == 4">
          <el-col :span="5">
            <span>大区经理姓名：</span>
          </el-col>
          <el-col :span="18">
            <el-select v-model="userNameValue2"  filterable placeholder="请选择"   @change="changeAdd2" value-key="id" style="width: 100%;">
            <el-option
              v-for="item in userName"
              :key="item.id"
              :label="item.realName"
              :value="item.id">
            </el-option>
          </el-select>
          </el-col>
        </el-row>
        <el-row v-if="!dataFormAdd.id&dataFormAdd.assignmentType == 4">
          <el-col :span="5">
            <span>用户名：</span>
          </el-col>
          <el-col :span="18">
            <el-input v-model="dataFormAdd.userNames" disabled="true"></el-input>
          </el-select>
          </el-col>
        </el-row>
      <el-row v-if="!dataFormAdd.id&dataFormAdd.assignmentType == 1">
        <el-col :span="5">
          <span>分中心编码：</span>
        </el-col>
        <el-col :span="18">
          <el-input v-model="dataFormAdd.centerCode" auto-complete="off" :disabled="true"></el-input>
        </el-col>
      </el-row>
      <el-row v-if="dataFormAdd.id">
        <el-col :span="5">
          <span>备注：</span>
        </el-col>
        <el-col :span="18">
            <el-input v-model="dataFormAdd.remark" auto-complete="off"></el-input>
        </el-col>
      </el-row>
        <!-- <el-form-item label="分中心" prop="assignor" v-if="!dataFormAdd.id&dataFormAdd.assignmentType == 1">
          <el-select v-model="value2"  filterable placeholder="请选择"  @change="changeAdd(value2)" value-key="id"
                    style="width: 100%;">
            <el-option
              v-for="item in branchcenter"
              :key="item.id"
              :label="item.name"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item> -->
        <!-- <el-form-item label="分中心编码" prop="centerCode"  v-if="!dataFormAdd.id&dataFormAdd.assignmentType == 1">
          <el-input v-model="dataFormAdd.centerCode" auto-complete="off" :disabled="true"></el-input>
        </el-form-item> -->
        <!-- <el-form-item label="备注" prop="remark" v-if="dataFormAdd.id">
          <el-input v-model="dataFormAdd.remark" auto-complete="off"></el-input>
        </el-form-item> -->

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :size="size" @click.native="dialogVisible = false">{{$t('action.cancel')}}</el-button>
        <el-button :size="size" authType="primary" @click.native="submitForm" :loading="editLoading" v-if="!dataFormAdd.id">{{$t('action.submit')}}</el-button>
        <el-button :size="size" authType="primary" @click.native="submitFormEdit" :loading="editLoading" v-if="dataFormAdd.id">{{$t('action.submit')}}</el-button>
      </div>
    </el-dialog>
    <!--分配-->
    <el-dialog :title="'分配'" width="30%" :visible.sync="distribution" :close-on-click-modal="false">
      <el-form :model="dataFormAdd" label-width="100px" :rules="dataFormRules" ref="dataFormAdd" :size="size">
        <el-form-item label="ID" prop="id" v-if="false">
          <el-input v-model="dataFormAdd.id" :disabled="true" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="分配至" prop="assignmentType"  >
          <el-select v-model="dataFormAdd.assignmentType" clearable  filterable placeholder="请选择"   value-key="id" style="width: 100%;">
            <el-option
              v-for="item in assignmentType"
              :key="item.key"
              :label="item.value"
              :value="item.key">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="分中心" prop="assignor" v-if="dataFormAdd.assignmentType == 1">
          <el-select v-model="value2"  filterable  placeholder="请选择"  @change="changeAdd(value2)" value-key="id"
                    style="width: 100%;">
            <el-option
              v-for="item in branchcenter"
              :key="item.id"
              :label="item.name"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="分中心编码" prop="centerCode"  v-if="dataFormAdd.assignmentType == 1">
          <el-input v-model="dataFormAdd.centerCode" auto-complete="off" :disabled="true"></el-input>
        </el-form-item>
        <el-form-item label="大区经理姓名"  prop="userNameValue" v-if="dataFormAdd.assignmentType == 4">
          <el-select v-model="userNameValue3"  filterable placeholder="请选择"   @change="changeAdd3" value-key="id" style="width: 100%;">
            <el-option
              v-for="item in userName"
              :key="item.id"
              :label="item.realName"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="用户名"  v-if="dataFormAdd.assignmentType == 4">
          <el-input v-model="dataFormAdd.userNames" auto-complete="off" :disabled="true"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :size="size" @click.native="distribution = false">{{$t('action.cancel')}}</el-button>
        <el-button :size="size" @click.native="distributionForm">{{$t('action.submit')}}</el-button>
      </div>
    </el-dialog>
    <!--批量分配-->
    <el-dialog :title="'批量分配'" width="30%" :visible.sync="batch_distribution" :close-on-click-modal="false">
      <div style="margin-bottom: 10px;color: red">已选{{selections.length}}张卡</div>
      <el-form :model="dataFormAdd" label-width="100px" :rules="dataFormRules" ref="dataFormAdd" :size="size">
        <el-form-item label="ID" prop="id" v-if="false">
          <el-input v-model="dataFormAdd.id" :disabled="true" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="分配至" prop="assignmentType"  >
          <el-select v-model="dataFormAdd.assignmentType" clearable  filterable placeholder="请选择"   value-key="id" style="width: 100%;">
            <el-option
              v-for="item in assignmentType"
              :key="item.key"
              :label="item.value"
              :value="item.key">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="分中心" prop="assignor" v-if="dataFormAdd.assignmentType == 1">
          <el-select v-model="value2"  filterable placeholder="请选择"   @change="changeAdd(value2)" value-key="id" style="width: 100%;">
            <el-option
              v-for="item in branchcenter"
              :key="item.id"
              :label="item.name"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="大区经理姓名" prop="userNameValue" v-if="dataFormAdd.assignmentType == 4">
          <el-select v-model="userNameValue4"  filterable placeholder="请选择"   @change="changeAdd4" value-key="id" style="width: 100%;">
            <el-option
              v-for="item in userName"
              :key="item.id"
              :label="item.realName"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="用户名"  v-if="dataFormAdd.assignmentType == 4">
          <el-input v-model="dataFormAdd.userNames" auto-complete="off" :disabled="true"></el-input>
        </el-form-item>
        <el-form-item label="分中心编码" prop="centerCode"  v-if="dataFormAdd.assignmentType == 1">
          <el-input v-model="dataFormAdd.centerCode" auto-complete="off" :disabled="true"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :size="size" @click.native="batch_distribution = false">{{$t('action.cancel')}}</el-button>
        <el-button :size="size" @click.native="distributionForm">{{$t('action.submit')}}</el-button>
      </div>
    </el-dialog>
    <!--文件上传-->
    <!--导入-->
    <el-dialog :title="'批量导入'" width="30%" class="uploadOem" :visible.sync="uploadOem" :close-on-click-modal="false" :before-close="uploadClose">
      <!-- <el-form :model="form" > -->
      <el-form :model="uploadData" >
        <el-form-item >
          <el-row>
            <el-col :span="5">
              <span>使用方式：</span>
            </el-col>
            <el-col :span="18">
              <el-select v-model="uploadData.useType"  @change="useTypeChange" filterable placeholder="请选择" clearable
                      style="width: 100%;">
              <el-option
                v-for="item in useWay"
                :key="item.key"
                :label="item.value"
                :value="item.key">
              </el-option>
            </el-select>
            </el-col>
          </el-row> 
          <el-row v-if='isSchoolType'>
            <el-col :span="5">
              <span>学校：</span>
            </el-col>
            <el-col :span="18">
              <el-select v-model="uploadData.schoolId" filterable placeholder="请选择" clearable
                      style="width: 100%;">
              <el-option
                v-for="item in school_option"
                :key="item.id"
                :label="item.schoolName"
                :value="item.id">
              </el-option>
            </el-select>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="5">
              <span>三方：</span>
            </el-col>
            <el-col :span="18">
              <el-select v-model="uploadData.frontUserId" filterable placeholder="请选择" clearable
                      style="width: 100%;">
              <el-option
                v-for="item in SF_option"
                :key="item.id"
                :label="item.userName"
                :value="item.id">
              </el-option>
            </el-select>
            </el-col>
          </el-row>
          <el-row v-if='isSchoolType'>
            <el-col :span="5">
              <span>班级名称：</span>
            </el-col>
            <el-col :span="18">
              <el-input v-model="uploadData.clazzName"></el-input>
            </el-col>
          </el-row> 
        </el-form-item>
        <el-form-item v-if='isShowUpload'>
          <el-upload
            ref="uploadExcel"
            :action='uploadUrl'
            :limit='limitNum'
            :auto-upload="false"
            accept=".xls"
            :before-upload="beforeUploadFile"
            :on-change="fileChange"
            :on-exceed="exceedFile"
            :on-success="handleSuccess"
            :on-error="handleError"
            :file-list="fileList">
            <el-button size="small"  plain>选择文件上传</el-button>
            <div slot="tip" class="el-upload__tip">只能上传xls(Excel2007)文件</div>
          </el-upload>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :size="size" @click.native="uploadClose">{{$t('action.cancel')}}</el-button>
        <el-button :size="size" type="primary" @click.native="uploadFile">{{('立即上传')}}</el-button>
      </div>
    </el-dialog>
    <!-- 导入更新 -->
    <el-dialog :title="'批量更新信息'" width="35%" class="uploadOem uploadOem2" :visible.sync="uploadOemUpdate" :close-on-click-modal="false" :before-close="uploadUpdateClose">
      <!-- <el-form :model="form" > -->
      <el-form :model="OEMUpdateForm" >
        <el-form-item >
          <el-row>
          
            
              <el-form-item label="限制激活截止时间" prop="assignmentType" >
              <el-date-picker
              @change='updateOEMdate'
                    v-model="OEMUpdateForm.limitedActivationStopDate"
                    type="date"
                    value-format="yyyy-MM-dd HH:mm:ss"
                    format="yyyy-MM-dd HH:mm:ss">
                </el-date-picker>
            
            </el-form-item>
          </el-row> 
          <el-row>
            
          <el-form-item label="分配至" prop="assignmentType" style="margin: 20px 0;">
          <el-select v-model="OEMUpdateForm.assignmentType" clearable  filterable placeholder="请选择" @change="changeUpdateOEMAdd2"  value-key="id">
            <el-option
              v-for="item in assignmentType"
              :key="item.key"
              :label="item.value"
              :value="item.key">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="分中心" prop="assignor" v-if="OEMUpdateForm.assignmentType == 1">
          <el-select v-model="value2"  filterable placeholder="请选择"   @change="changeAddUP(value2)" value-key="id">
            <el-option
              v-for="item in branchcenter"
              :key="item.id"
              :label="item.name"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="大区经理姓名" prop="userNameValue" v-if="OEMUpdateForm.assignmentType == 4">
          <el-select v-model="userNameValue4"  filterable placeholder="请选择"   @change="changeAddUP2" value-key="id">
            <el-option
              v-for="item in userName"
              :key="item.id"
              :label="item.realName"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="用户名"  v-if="OEMUpdateForm.assignmentType == 4" style="margin:20px 0;">
          <el-input v-model="dataFormAdd.userNames" auto-complete="off" :disabled="true" style="width: 70%;"></el-input>
        </el-form-item>
        <el-form-item label="分中心编码" prop="centerCode"  v-if="OEMUpdateForm.assignmentType == 1" style="margin:20px 0;">
          <el-input v-model="dataFormAdd.centerCode" auto-complete="off" :disabled="true" style="width: 70%;"></el-input>
        </el-form-item>
            
          </el-row> 
        </el-form-item>
      <div class="rule">
        <div class="title">规则</div>
        <div class="rule-cont">
          <p> 1.之前分配类型为分中心或大区经理的OEM卡不可批量更新分配类型为网推中心类型</p>
          <p>2.之前类型为网推中心的OEM卡不可批量更新分配类型为分中心或大区经理类型</p>
        </div>        
      </div>
        <el-form-item v-if='isUpdateOEM'>
          <el-upload
            ref="uploadExcel"
            :action='uploadUrl'
            :limit='limitNum'
            :auto-upload="false"
            accept=".xls"
            :before-upload="beforeUploadFile"
            :on-change="fileChange" 
            :on-exceed="exceedFile"
            :on-success="handleSuccess"
            :on-error="handleError"
            :file-list="fileList">
            <el-button size="small"  plain>选择文件上传</el-button>
            <div slot="tip" class="el-upload__tip">只能上传xls(Excel2007)文件</div>
          </el-upload>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer" style="clear:both">
        <el-button :size="size" @click.native="uploadUpdateClose">{{$t('action.cancel')}}</el-button>
        <el-button :size="size" type="primary" @click.native="uploadFileupdate">{{('立即上传')}}</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import PopupTreeInput from "@/components/PopupTreeInput";
import CrmTreeInput from "@/components/CrmTreeInput";
import KtButton from "@/views/Core/KtButton";
import KtTable from "@/views/Core/KtTable";
import axios from "axios";
import { baseUrl } from "@/utils/global";
export default {
  name: "o-e-m",
  components: {
    PopupTreeInput,
    KtButton,
    KtTable,
    CrmTreeInput
  },
  data() {
    return {
      size: "small",
      filters: {
        name: ""
      },
      uploadOem: false, //文件上传
      limitNum: 1, //上传最大个数
      form: {
        file: ""
      },
      fileList: [],
      uploadUrl: baseUrl + "/file/upload", //文件上传地址
      downloadUrl: baseUrl + "/oemInfo/downExcelModel", //下载导入模板地址
      exportOemUrl: baseUrl + "/oemInfo/exportOemInfo", //导出地址
      columns: [
        { type: "index", label: "序号", minWidth: 50 },
        { prop: "cardNumber", label: "OEM卡号", minWidth: 150 },
        { prop: "cardPassword", label: "密码", minWidth: 80 },
        { prop: "cardTypeName", label: "类型", minWidth: 80 },
        { prop: "cardFrom", label: "种类", minWidth: 80 },
        { prop: "subject", label: "科目", minWidth: 80 },
        { prop: "centerCode", label: "分配至", minWidth: 100 },
        { prop: "activationDate", label: "激活时间", minWidth: 100 },
        { prop: "activationPhone", label: "激活手机号", minWidth: 100 },
        { prop: "remark", label: "备注", minWidth: 120 },
        { prop: "createDate", label: "创建时间", minWidth: 190 }
      ],
      pageRequest: { pageNum: 1, pageSize: 8 },
      pageResult: {
        content: [],
        totalSize: ""
      },
      operation: false, // true:新增, false:编辑
      dialogVisible: false, // 新增编辑界面是否显示
      distribution: false, // 分配界面是否显示
      batch_distribution: false, // 批量界面是否显示
      editLoading: false,
      OEM: true,
      dataFormRules: {
        // assignor: [{ required: true, message: "请选择分中心", trigger: "blur" }]
      },
      userName: [],
      userNameValue: "",
      userNameValue2: "",
      userNameValue3: "",
      userNameValue4: "",
      // 界面数据
      dataForm: {
        cardNumber: "",
        cardType: "",
        assignor: "",
        remark: "",
        createDate: "",
        oemTypevalue: "",
        oemStatusvalue: "",
        activationStatus: "",
        startCardNumber: "",
        endCardNumber: "",
        userNameValue: "",
        cardFrom: ""
      },
      //新增数据
      dataFormAdd: {
        id: "",
        cardNumber: "",
        cardPassword: "",
        cardType: "",
        assignor: "",
        activationDate: "",
        activationPhone: "",
        remark: "",
        oemTypevalue: "",
        oemStatusvalue: "",
        assignmentTypevalue: "",
        activationStatus: "",
        centerCode: "",
        openNumber: "",
        assignmentType: "",
        limitedActivationStartDate: "",
        limitedActivationStopDate: "",
        startCardNumber: "",
        endCardNumber: "",
        userNameValue: "",
        schoolName: "",
        useType: ""
      },
      selections: [], //选中列表集合
      oemStatus: [], // 是否激活下拉框
      oemStatusProps: {
        label: "value",
        children: "children"
      },
      oemType: [], // oem类型
      oemSubject: [], // 科目
      assignmentType: [], //分配至下拉框
      branchcenter: [], //分中心下拉框
      value: "", //分中心
      value2: "", //新增分中心
      value3: "", //周卡月卡回显
      value4: "", //网推中心分中心回显
      cardFrom: "", //OEK种类
      activationDate: [], //有效期
      cardFromOption: [],
      ids: [], //分配id集合
      // 限制跟进时间
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() < Date.now() - 8.64e7; //如果没有后面的-8.64e7就是不可以选择今天的
        }
      },
      importIsSuccess: false, //导入是否成功
      useWay: [
        {
          key: "2",
          value: "B端"
        },
        {
          key: "1",
          value: "C端"
        }
      ],
      isSchoolType: false,
      school_option: [],
      SF_option: [],
      uploadData: {
        clazzName: "",
        frontUserId: "",
        schoolId: "",
        useType: ""
      },
      OEMUpdateForm: {
        // limitedActivationStopDate:''
      },
      isShowUpload: false,
      uploadOemUpdate: false,
      isUpdateOEM: false,
      importIsSuccess2: false,
      updateOEMsubcenter: ""
    };
  },
  methods: {
    //分中心选取
    change: function(value) {
      this.dataForm.assignor = value.toString();
    },
    //新增分中心选取
    changeAdd: function(value) {
      this.dataFormAdd.assignor = value.toString();
      for (let i = 0; i < this.branchcenter.length; i++) {
        if (this.dataFormAdd.assignor == this.branchcenter[i].id) {
          this.dataFormAdd.centerCode = this.branchcenter[i].code;
        }
      }
    },
    changeAddUP: function(value) {
      this.OEMUpdateForm.assignor = value.toString();
      for (let i = 0; i < this.branchcenter.length; i++) {
        if (this.OEMUpdateForm.assignor == this.branchcenter[i].id) {
          this.dataFormAdd.centerCode = this.branchcenter[i].code;
        }
      }
      if (this.OEMUpdateForm.assignor) {
        this.isUpdateOEM = true;
      }
      if (!this.OEMUpdateForm.assignor && !this.OEMUpdateForm.assignmentType) {
        this.isUpdateOEM = false;
      }
    },
    changeAddUP2: function(value) {
      this.OEMUpdateForm.assignor = value.toString();
      this.userNameValue4 = value;
      this.userName.forEach(item => {
        if (item.id == this.userNameValue4) {
          this.dataFormAdd.userNames = item.userName;
        }
      });
      if (this.OEMUpdateForm.assignor) {
        this.isUpdateOEM = true;
      }
      if (!this.OEMUpdateForm.assignor && !this.OEMUpdateForm.assignmentType) {
        this.isUpdateOEM = false;
      }
    },
    changeAdd2(value) {
      this.dataFormAdd.assignor = value.toString();
      this.userNameValue2 = value;
      this.userName.forEach(item => {
        if (item.id == this.userNameValue2) {
          this.dataFormAdd.userNames = item.userName;
        }
      });
    },
    changeAdd3(value) {
      this.dataFormAdd.assignor = value.toString();
      this.userNameValue3 = value;
      this.userName.forEach(item => {
        if (item.id == this.userNameValue3) {
          this.dataFormAdd.userNames = item.userName;
        }
      });
    },
    changeAdd4(value) {
      this.dataFormAdd.assignor = value.toString();
      this.userNameValue4 = value;
      this.userName.forEach(item => {
        if (item.id == this.userNameValue4) {
          this.dataFormAdd.userNames = item.userName;
        }
      });
    },
    //oem类型
    changeoemType: function(value) {
      this.dataFormAdd.cardType = value.toString();
    },
    changecardFrom: function(value) {
      this.cardFrom = value.toString();
    },
    //获取下拉列表
    findDown: function() {
      this.$api.dropdown.oemStatus().then(res => {
        this.oemStatus = res.keyValueList;
      });
      this.$api.dropdown.oemType().then(res => {
        this.oemType = res.keyValueList;
      });
      this.$api.dropdown.cardFrom().then(res => {
        this.cardFromOption = res.keyValueList;
      });
      this.$api.dropdown.assignmentType().then(res => {
        this.assignmentType = res.keyValueList;
      });
      this.$api.dropdown.branchcenter().then(res => {
        this.branchcenter = res.branchCenterInfoList;
      });
      this.$api.dropdown.oemSubject().then(res => {
        this.oemSubject = res.keyValueList;
      });
      this.$api.person.cacheFontList({ userType: "1" }).then(res => {
        
      });
      this.SF_option = JSON.parse(localStorage.getItem('SFcacheList'))
      this.$api.dropdown
        .users({
          userType: 3,
          deptType: 4,
          isControlResource: 1,
          accountStatus: 1
        })
        .then(res => {
          if (res.result == 1) {
            this.userName = res.userInfoList;
          }
        });
      this.$api.oem.schoolList().then(res => {
        this.school_option = res.data;
      });
    },
    // 下拉框选中选中
    handleTreeSelectChange(data, node) {
      this.dataForm.activationStatus = data.key;
      this.dataForm.oemStatusvalue = data.value;
    },
    handleTreeSelectChange2(data, node) {
      this.dataForm.oemTypevalue = data.value;
      this.dataForm.cardType = data.key;
    },
    handleTreeSelectChange3Add(data, node) {
      this.dataFormAdd.assignmentTypevalue = data.value;
      this.value4 = data.value;
      this.dataFormAdd.assignmentType = data.key;
    },
    //表单重置
    resetForm(dataForm) {
      this.dataForm.oemTypevalue = "";
      this.dataForm.oemStatusvalue = "";
      this.dataForm.createDate = "";
      this.dataForm.cardNumber = "";
      this.dataForm.assignor=''
      this.selections=[]
      this.dataForm.activationStatus = "";
      this.value = "";
      this.dataForm.remark = "";
      this.$refs.dataForm.resetFields();
      this.dataForm.cardType = "";
      this.editLoading = false;
      this.dataForm.startCardNumber = "";
      this.dataForm.endCardNumber = "";
      this.dataForm.cardFrom = "";
      this.findPage(null);
    },
    // 获取分页数据
    findPage: function(data) {
      // if (data !== null) {
      //   this.pageRequest = data.pageRequest;
      //   this.pageRequest = Object.assign({},this.pageRequest,this.data)
      // }
      if (data !== null) {
        this.loading = true;
        this.pageRequest = data.pageRequest;
      }
      this.dataForm.pageSize = this.pageRequest.pageSize;
      this.dataForm.pageNum = this.pageRequest.pageNum;
      // this.pageRequest.columnFilters = {
      //   name: { name: "name", value: this.filters.name }
      // };
      this.$api.oem
        .findPage(this.dataForm)
        .then(res => {
          this.pageResult.content = res.oemInfoList;
          this.pageResult.totalSize = res.total;
        })
        .then(data != null ? data.callback : "");
    },
    // 批量删除
    handleBatchDelete: function(data) {
      let oemInfoIds = data.params[0];
      this.$api.oem
        .handleBatchDelete({ oemInfoIds: oemInfoIds })
        .then(data != null ? data.callback : "");
    },
    // 删除
    handleDelete: function(data) {
      let oemInfoId = data.params[0].id;
      this.$api.oem
        .batchDelete({ oemInfoId: oemInfoId })
        .then(data != null ? data.callback : "");
    },
    //查询
    searchForm: function() {
      this.$refs.dataForm.validate(valid => {
        if (valid) {
          this.data = {
            cardNumber: this.dataForm.cardNumber,
            cardType: this.dataForm.cardType,
            assignor: this.dataForm.assignor,
            activationStatus: this.dataForm.activationStatus,
            remark: this.dataForm.remark,
            createStartDate: this.dataForm.createDate[0],
            createStopDate: this.dataForm.createDate[1],
            startCardNumber: this.dataForm.startCardNumber,
            endCardNumber: this.dataForm.endCardNumber,
            cardFrom: this.dataForm.cardFrom
          };
          this.editLoading = true;
          let params = Object.assign({}, this.data, this.pageRequest);
          this.$api.oem.findPage(params).then(res => {
            this.editLoading = false;
            if (res.result == 1) {
              this.pageResult.content = res.oemInfoList;
              this.pageResult.totalSize = res.total;
              // this.$refs["dataForm"].resetFields();
            }
          });
        }
      });
    },
    // 显示新增界面
    handleAdd: function() {
      this.dialogVisible = true;
      this.operation = true;
      this.value3 = "";
      this.value2 = "";
      this.value4 = "";
      this.userNameValue = "";
      this.userNameValue2 = "";
      this.userNameValue3 = "";
      this.userNameValue4 = "";
      this.cardFrom = "1";
      this.activationDate = [];
      this.dataFormAdd = {
        id: "",
        cardNumber: "",
        openNumber: "",
        cardPassword: "",
        cardType: "",
        assignor: "",
        activationDate: "",
        activationPhone: "",
        remark: "",
        createDate: "",
        oemTypevalue: "",
        oemStatusvalue: "",
        assignmentType: "",
        assignmentTypevalue: "",
        centerCode: "",
        subject: ""
      };
    },
    // 显示编辑界面
    handleEdit: function(params) {
      // 跟进当前ID查询当前的信息防止科目提汉字
      this.$api.oem.search({ oemInfoId: params.row.id }).then(res => {
        this.dataFormAdd.subject = res.oemInfo.subject;
      });
      this.dialogVisible = true;
      this.operation = false;
      this.cardFrom = params.row.cardFrom;

      this.activationDate = [];
      for (let i = 0; i < this.oemType.length; i++) {
        if (params.row.cardType == this.oemType[i].key) {
          this.value3 = this.oemType[i].value;
        }
      }
      this.activationDate.push(
        params.row.limitedActivationStartDate,
        params.row.limitedActivationStopDate
      );
      this.dataFormAdd = Object.assign({}, params.row);
      if (this.dataFormAdd.useType == 2) {
        this.dataFormAdd.useType = "B端";
        this.isSchoolType = true;
      }
      if (this.dataFormAdd.useType == 1) {
        this.dataFormAdd.useType = "C端";
        this.isSchoolType = false;
      }
    },
    // 显示分配界面
    distributionoem: function(params) {
      this.distribution = true;
      this.ids = [];
      this.userNameValue = "";
      this.userNameValue2 = "";
      this.userNameValue3 = "";
      this.userNameValue4 = "";
      this.dataFormAdd = Object.assign({}, params.row);
      this.dataFormAdd.assignmentType = JSON.stringify(
        this.dataFormAdd.assignmentType
      );
      if (this.dataFormAdd.assignmentType == "null") {
        this.dataFormAdd.assignmentType = "";
      }
      this.value2 = this.dataFormAdd.assignor;
      for (let i = 0; i < this.branchcenter.length; i++) {
        if (this.value2 == this.branchcenter[i].id) {
          this.dataFormAdd.centerCode = this.branchcenter[i].code;
        }
      }
      this.ids.push(this.dataFormAdd.id);
    },
    // 显示批量分配界面
    batchDistributionoem: function() {
      this.dataFormAdd = {
        ids: "",
        assignor: "",
        centerCode: "",
        assignmentType: ""
      };
      this.value4 = "";
      this.value2 = "";
      this.userNameValue = "";
      this.userNameValue2 = "";
      this.userNameValue3 = "";
      this.userNameValue4 = "";
      this.batch_distribution = true;
      this.ids = [];
      let idsoem = this.selections.map(item => item.id);
      // this.dataFormAdd = Object.assign({}, params.row);
      this.ids = idsoem;
    },
    // 获取选中的表格数据
    selectionChange: function(selections) {
      this.selections = selections.selections;
    },
    // 新增提交
    submitForm: function() {
      if (this.dataFormAdd.useType == 2) {
        if (
          this.dataFormAdd.schoolId == "" ||
          this.dataFormAdd.schoolId == null
        ) {
          this.$message({
            message: "请选择学校",
            type: "error"
          });
          return;
        }
        this.editLoading = false;
      }
      this.$refs.dataFormAdd.validate(valid => {
        if (valid) {
          this.$confirm("确认提交吗？", "提示", {}).then(() => {
            // this.dataAdd={
            //   openNumber:this.dataFormAdd.openNumber,
            //   cardType:this.dataFormAdd.cardType,
            //   assignor:this.dataFormAdd.assignor,
            //   centerCode:this.dataFormAdd.centerCode,
            //   subject:this.dataFormAdd.subject,
            //   assignmentType:this.dataFormAdd.assignmentType,
            //   cardFrom:this.cardFrom,
            //   limitedActivationStartDate:this.activationDate[0],
            //   limitedActivationStopDate:this.activationDate[1]
            // }
            this.dataFormAdd.limitedActivationStartDate = this.activationDate[0];
            this.dataFormAdd.limitedActivationStopDate = this.activationDate[1];
            this.dataFormAdd.cardFrom = this.cardFrom;
            this.editLoading = true;
            let params = Object.assign({}, this.dataFormAdd);
            this.$api.oem.save(params).then(res => {
              this.editLoading = false;
              if (res.result == 1) {
                this.$message({ message: res.msg, type: "success" });
                this.dialogVisible = false;
                this.$refs["dataForm"].resetFields();
                this.userNameValue = "";
                this.userNameValue2 = "";
                this.userNameValue3 = "";
                this.userNameValue4 = "";
              } else {
                this.$message({
                  message: res.msg,
                  type: "error"
                });
              }
              this.findPage(null);
            });
          });
        }
      });
    },
    // 编辑提交
    submitFormEdit: function() {
      this.$refs.dataFormAdd.validate(valid => {
        if (this.dataFormAdd.useType == "B端") {
          this.dataFormAdd.useType = 2;
        }
        if (this.dataFormAdd.useType == "C端") {
          this.dataFormAdd.useType = 1;
        }
        if (this.dataFormAdd.useType == 2) {
          if (
            this.dataFormAdd.schoolId == "" ||
            this.dataFormAdd.schoolId == null
          ) {
            this.$message({
              message: "请选择学校",
              type: "error"
            });
            return;
          }
          this.editLoading = false;
        }
        if (valid) {
          this.$confirm("确认提交吗？", "提示", {}).then(() => {
            this.dataEdit = {
              id: this.dataFormAdd.id,
              cardNumber: this.dataFormAdd.cardNumber,
              cardPassword: this.dataFormAdd.cardPassword,
              cardType: this.dataFormAdd.cardType,
              remark: this.dataFormAdd.remark,
              subject: this.dataFormAdd.subject,
              limitedActivationStartDate: this.activationDate[0],
              limitedActivationStopDate: this.activationDate[1],
              useType: this.dataFormAdd.useType,
              schoolId:
                this.dataFormAdd.useType == 2 ? this.dataFormAdd.schoolId : ""
            };
            this.editLoading = true;
            let params = Object.assign({}, this.dataEdit);

            this.$api.oem.edit(params).then(res => {
              this.editLoading = false;
              if (res.result == 1) {
                this.$message({ message: res.msg, type: "success" });
                this.dialogVisible = false;
                this.$refs["dataForm"].resetFields();
                this.userNameValue = "";
                this.userNameValue2 = "";
                this.userNameValue3 = "";
                this.userNameValue4 = "";
              } else {
                this.$message({
                  message: res.msg,
                  type: "error"
                });
              }
              this.findPage(null);
            });
          });
        }
      });
    },
    // 分配提交
    distributionForm: function() {
      this.$refs.dataFormAdd.validate(valid => {
        if (valid) {
          this.$confirm("确认提交吗？", "提示", {}).then(() => {
            this.datadistribution = {
              ids: this.ids,
              assignor: this.dataFormAdd.assignor,
              centerCode: this.dataFormAdd.centerCode,
              assignmentType: this.dataFormAdd.assignmentType
            };
            let params = Object.assign({}, this.datadistribution);
            this.$api.oem.distribution(params).then(res => {
              this.distribution = false;
              this.batch_distribution = false;
              if (res.result == 1) {
                this.$message({ message: res.msg, type: "success" });
                this.dialogVisible = false;
                this.$refs["dataForm"].resetFields();
              } else {
                this.$message({
                  message: res.msg,
                  type: "error"
                });
              }
              this.findPage(null);
            });
          });
        }
      });
    },
    // 菜单树选中
    deptTreeCurrentChangeHandle(data, node) {
      this.dataForm.deptId = data.id;
      this.dataForm.deptName = data.name;
    },
    //批量导入
    batchImport: function() {
      this.uploadOem = true;
      this.$api.person.cacheFontList({ userType: "1" }).then(res => {
        this.SF_option = res.data;
      });
    },
    uploadClose: function() {
      this.uploadOem = false;
      this.uploadData = {
        useType: "",
        schoolId: "",
        frontUserId: "",
        clazzName: ""
      };
    },
    // 文件超出个数限制时的钩子
    exceedFile(files, fileList) {
      this.$notify.warning({
        title: "警告",
        message: `只能选择 ${
          this.limitNum
        } 个文件，当前共选择了 ${files.length + fileList.length} 个`
      });
    },
    // 文件状态改变时的钩子
    fileChange(file, fileList) {
      this.form.file = file.raw;
    },
    // 上传文件之前的钩子, 参数为上传的文件,若返回 false 或者返回 Promise 且被 reject，则停止上传
    beforeUploadFile(file) {
      let extension = file.name.substring(file.name.lastIndexOf(".") + 1);
      let size = file.size / 1024 / 1024;
      if (extension !== "xls") {
        this.$notify.warning({
          title: "警告",
          message: `只能上传Excel（即后缀是.xls）的文件`
        });
        0;
      }
    },
    // 文件上传成功时的钩子
    handleSuccess(res, file, fileList) {
      this.$refs.uploadExcel.clearFiles();
      this.$notify.success({
        title: "成功",
        message: `文件上传成功,数据处理中,稍后在我的消息中查看！`
      });
    },
    // 文件上传失败时的钩子
    handleError(err, file, fileList) {
      this.$notify.error({
        title: "错误",
        message: `文件上传失败`
      });
    },
    uploadFile() {
      this.importIsSuccess = true;
      let formData = new FormData();
      formData.append("file", this.form.file);
      axios
        .post(this.uploadUrl, formData, {
          "Content-Type": "multipart/form-data"
        })
        .then(res => {
          if (res.data.result == 1) {
            let path = res.data.fileUrl;
            this.uploadData.path = path;
            this.$api.oem.importOem(this.uploadData).then(res => {
              if (res.result == 1) {
                this.handleSuccess();
                this.uploadOem = false;
                this.importIsSuccess = false;
              } else {
                this.importIsSuccess = false;
                this.$message({
                  message: res.msg,
                  type: "error"
                });
              }
            });
          } else {
            this.handleError();
          }
        });
    },
    uploadFileupdate() {
      this.importIsSuccess2 = true;
      let formData = new FormData();
      formData.append("file", this.form.file);
      axios
        .post(this.uploadUrl, formData, {
          "Content-Type": "multipart/form-data"
        })
        .then(res => {
          if (res.data.result == 1) {
            let path = res.data.fileUrl;
            if (!this.OEMUpdateForm.limitedActivationStopDate) {
              this.OEMUpdateForm.limitedActivationStopDate = "";
            }
            this.OEMUpdateForm.filePath = path;
            this.$api.oem.batchUpdateInfo(this.OEMUpdateForm).then(res => {
              if (res.result == 1) {
                this.handleSuccess();
                this.uploadOemUpdate = false;
                this.importIsSuccess2 = false;
                this.uploadData = {
                  assignmentType: "",
                  assignor: "",
                  limitedActivationStopDate: ""
                };
                this.OEMUpdateForm = {
                  assignmentType: "",
                  assignor: "",
                  limitedActivationStopDate: ""
                };
              } else {
                this.importIsSuccess2 = false;
                this.$message({
                  message: res.msg,
                  type: "error"
                });
              }
            });
          } else {
            this.handleError();
          }
        });
    },
    //下载导入模板
    download: function() {
      window.open(this.downloadUrl);
    },
    // 下载更新模板
    downloadUpdate() {
      this.getOEMUpdateTempl();
    },
    batchUpdate() {
      this.uploadOemUpdate = true;
    },
    uploadUpdateClose: function() {
      this.uploadOemUpdate = false;
      this.uploadData = {
        assignmentType: "",
        assignor: "",
        limitedActivationStopDate: ""
      };
      this.OEMUpdateForm = {
        assignmentType: "",
        assignor: "",
        limitedActivationStopDate: ""
      };
      this.isUpdateOEM = false;
    },
    updateOEMdate(value) {
      this.OEMUpdateForm.limitedActivationStopDate = value;
      if (this.OEMUpdateForm.limitedActivationStopDate) {
        this.isUpdateOEM = true;
      }
      if (
        !this.OEMUpdateForm.limitedActivationStopDate &&
        !this.OEMUpdateForm.assignmentType
      ) {
        this.isUpdateOEM = false;
      }
    },
    changeUpdateOEMAdd2(value) {
      if (this.OEMUpdateForm.assignor) {
        this.isUpdateOEM = true;
      }
      if (!this.OEMUpdateForm.assignor && !this.OEMUpdateForm.assignmentType) {
        this.isUpdateOEM = false;
      }
      if (value == "") {
        this.isUpdateOEM = false;
      }
      if (value == 2) {
        this.isUpdateOEM = true;
      }
    },
    //导出
    exportOem: function() {
      this.$refs.dataForm.validate(valid => {
        if (valid) {
          this.data = {
            cardNumber: this.dataForm.cardNumber,
            cardType: this.dataForm.cardType,
            assignor: this.dataForm.assignor,
            activationStatus: this.dataForm.activationStatus,
            remark: this.dataForm.remark,
            createStartDate: this.dataForm.createDate[0],
            createStopDate: this.dataForm.createDate[1],
            startCardNumber:this.dataForm.startCardNumber,
            endCardNumber:this.dataForm.endCardNumber 
          };
          let params = Object.assign({}, this.data);
          axios({
            method: "get",
            url: this.exportOemUrl,
            params: params
          }).then(res => {
            window.open(res.request.responseURL);
          });
        }
      });
    },
    // 使用方式
    useTypeChange(e) {
      // 1:c 2:b
      if (e == 1) {
        this.isShowUpload = true;
        this.isSchoolType = false;
        this.uploadData.clazzName = "";
        this.uploadData.schoolId = "";
        this.uploadData.frontUserId = "";
      } else {
        this.isSchoolType = true;
        if (this.schoolChange) {
          this.isShowUpload = true;
        }
      }
    },
    schoolChange(e) {
      this.schoolChange = true;
    }
  },
  mounted() {
    this.findDown();
  }
};
</script>
<style>
@import url("../../assets/queryBox.css");
</style>

<style lang='scss' scoped>
.addNew .el-row {
  margin-top: 20px;
  text-align: left;
  margin-left: 15px;
}
.addNew .el-row .el-col span {
  display: inline-block;
  margin-top: 10px;
}
.uploadOem {
  .el-row {
    margin: 20px 0;
  }
}
</style>
<style lang="scss">
.uploadOem2 {
  .el-select {
    width: 70%;
  }

  .el-date-editor.el-input,
  .el-date-editor.el-input__inner {
    width: 70%;
  }
  .el-dialog__body .el-form-item__label{
    width: 125px!important;
  }
  .rule{
    color: red;
    font-size: 13px;
    margin-top: -20px;
    .title{
      float: left;
      width: 15%;
      text-align: right;
      margin-right: 20px;
    }
    .rule-cont{
      float: left;
      text-align: left;
      width: 80%;
      margin-top: -14px; 
    }
  }
}
</style>
